﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Common;

public class RegisterPanel : MonoBehaviour {
    
    public Button Button_register;
    public Button Button_back;
    public InputField InputField_username;
    public InputField InputField_password;
    public Text Text_hintMessage;

    public GameObject loginPanel;

    private RegisterRequest registerRequest;
    void Awake() {
        EventTriggerListener.Get(Button_register.gameObject, null).onClick = OnClick_Button_register;
        EventTriggerListener.Get(Button_back.gameObject, null).onClick = OnClick_Button_back;
    }
    void Start()
    {
        registerRequest = GetComponent<RegisterRequest>();
    }

    void OnClick_Button_register(GameObject go, object data = null)
    {
        Debug.Log("OnClick_Button_register");

        Text_hintMessage.text = "";
        registerRequest.Username = InputField_username.text;
        registerRequest.Password = InputField_password.text;
        registerRequest.DefaultRequest();
    }

    void OnClick_Button_back(GameObject go, object data = null)
    {
        Debug.Log("OnClick_Button_back");

        this.gameObject.SetActive(false);
        loginPanel.gameObject.SetActive(true);
    }

    public void OnRegisterResponse(ReturnCode returnCode)
    {
        if (returnCode == ReturnCode.Success)
        {
            Text_hintMessage.text = "注册成功~请返回登录";
        }
        else if(returnCode == ReturnCode.Failed)
        {
            Text_hintMessage.text = "注册失败~用户名重复，请更改用户名重新注册";
        }
    }
}
